package com.ruoyi.common.core.domain.model;

import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.module.SimpleModule;
import org.apache.dubbo.spring.security.jackson.ObjectMapperCodec;
import org.apache.dubbo.spring.security.jackson.ObjectMapperCodecCustomer;

import java.time.LocalDateTime;
import java.util.HashSet;

/**
 * @author gotanks
 * @create 2024/9/24
 */
public class LoginUserObjectMapperCodecCustomer implements ObjectMapperCodecCustomer {
    @Override
    public void customize(ObjectMapperCodec objectMapperCodec) {
        objectMapperCodec.addModule(new LoginUserModule());
    }

    public static class LoginUserModule extends SimpleModule {
        public LoginUserModule() {
            super(LoginUserModule.class.getName(), new Version(1, 0, 0, null, null, null));
        }

        @Override
        public void setupModule(SetupContext context) {
            context.setMixInAnnotations(LoginUser.class, LoginUserMixin.class);
            context.setMixInAnnotations(HashSet.class, LoginUserMixin.class);
            context.setMixInAnnotations(LocalDateTime.class, LoginUserMixin.class);
            context.setMixInAnnotations(Long.class, LoginUserMixin.class);
            context.setMixInAnnotations(String.class, LoginUserMixin.class);
        }
    }
}
